<?php
/*
 * This php script is used to try connecting our application to twitter. 
 */

//some requirements
//session_start();
require_once("twitteroauth/twitteroauth.php");
require_once("configuration.php");
include('session.php');

// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken(OAUTH_CALLBACK);

// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

// If everything goes well..
if($twitteroauth->http_code==200){
    // Let's generate the URL and redirect
    $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
    // $str ='<script type="text/javascript">window.location = "'.$url.'"</script>';
    header('Location: '. $url);
    //echo $str;
} else {
    // It's a bad idea to kill the script, but we've got to know when there's an error.
    die('Something wrong happened.');
}

?>
